package cn.com.headfree.mouldshow.service.impl;

//import cn.com.headfree.base.controller.ResultData;
//import cn.com.headfree.callback.call.FileServerCall;
//import cn.com.headfree.entity.*;
//import cn.com.headfree.mouldshow.controller.ExportWordController;

import cn.com.headfree.entity.TPartRank;
import cn.com.headfree.mouldshow.dao.HumanDataDao;
import cn.com.headfree.mouldshow.dao.TPartRankDao;
import cn.com.headfree.mouldshow.service.HumanDataService;
//import cn.com.headfree.vo.FileInfoVo;
import cn.com.headfree.util.SysDictionaryUtil;
import cn.com.headfree.vo.SysDictionaryInfoVo;
import cn.com.headfree.vo.simple.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.deepoove.poi.data.DocxRenderData;
//import feign.Response;
//import net.sf.json.JSONArray;
//import net.sf.json.JSONObject;
//import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
//import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
//import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service("humanDataService")
@Transactional
public class HumanDataServiceImpl implements HumanDataService {

    //    private static final Logger log=Logger.getLogger(HumanDataServiceImpl.class);
    private static final Logger log = LogManager.getLogger(HumanDataServiceImpl.class);

//    @Resource
//    private FileServerCall fileServerCall;

    @Resource
    private HumanDataDao humanDataDao;

    @Resource
    private TPartRankDao tPartRankDao;

    //获取待导出Word的各个模板数据
    public EmpBaseInfoVo getModelData(String erpNo, String pathOfTemplate) {
        Map<String, List<SysDictionaryInfoVo>> map = SysDictionaryUtil.getSysDictionaryList();

        List<EmpBaseInfoVo> tEmpBaseInfoPageList = humanDataDao.getTEmpBaseInfoPageList(erpNo, "");
        List<ContestInfoVo> tContestInfoPageList = humanDataDao.getTContestInfoPageList(erpNo, "");
        List<AcadeAchiveInfoVo> tAcadeAchiveInfoPageList = humanDataDao.getTAcadeAchiveInfoPageList(erpNo, "");
        List<ContiStudyInfoVo> tContiStudyInfoPageList = humanDataDao.getTContiStudyInfoPageList(erpNo, "");
        List<EducateInfoVo> tEducateInfoPageList = humanDataDao.getTEducateInfoPageList(erpNo, "");
        List<ExpertTitleInfoVo> tExpertTitleInfoPageList = humanDataDao.getTExpertTitleInfoPageList(erpNo, "");
        List<HonorInfoVo> tHonorInfoPageList = humanDataDao.getTHonorInfoPageList(erpNo, "");
        List<PatentInfoVo> tPatentInfoPageList = humanDataDao.getTPatentInfoPageList(erpNo, "");
        List<ProTecInfoVo> tProTecInfoPageList = humanDataDao.getTProTecInfoPageList(erpNo, "");
        List<ProjAchieveInfoVo> tProjAchieveInfoPageList = humanDataDao.getTProjAchieveInfoPageList(erpNo, "");
        List<SkillLevelInfoVo> tSkillLevelInfoPageList = humanDataDao.getTSkillLevelInfoPageList(erpNo, "");
        List<StandInfoVo> tStandInfoPageList = humanDataDao.getTStandInfoPageList(erpNo, "");
        List<TecInnovInfoVo> tTecInnovInfoPageList = humanDataDao.getTTecInnovInfoPageList(erpNo, "");
        List<TecManInnovVo> tTecManInnovPageList = humanDataDao.getTTecManInnovPageList(erpNo, "");
        List<WorkExpInfoVo> tWorkExpInfoPageList = humanDataDao.getTWorkExpInfoPageList(erpNo, "");
        List<YearEffectInfoVo> tYearEffectInfoPageList = humanDataDao.getTYearEffectInfoPageList(erpNo, "");
        List<SdtTutorPrentInfoVo> tSdtTutorPrentInfoPageList = humanDataDao.getTSdtTutorPrentInfoPageList(erpNo, "");

        //处理导师带徒的信息
        List<SdtTutorPrentInfoVo> tSdtTutorPrentInfoListNew = new ArrayList<>();
        if (tSdtTutorPrentInfoPageList != null && tSdtTutorPrentInfoPageList.size() > 0) {
            //获取不重复的id集合
            List<String> ids = new ArrayList<>();
            for (SdtTutorPrentInfoVo vo : tSdtTutorPrentInfoPageList) {
                if (!ids.contains(vo.getId())) {
                    ids.add(vo.getId());
                }
            }
            //重新组合数据
            for (String id : ids) {
                List<SdtPrentInfoVo> sdtPrentInfoVos = new ArrayList<>();
                //获取对应id的对象
                Optional<SdtTutorPrentInfoVo> first = tSdtTutorPrentInfoPageList.stream().filter(item -> item.getId().equals(id)).findFirst();
                if (first.isPresent()){
                    SdtTutorPrentInfoVo tutorNew = first.get();
                    //遍历导师集合,将id相同的师带徒信息的徒弟信息组合到一起
                    for (SdtTutorPrentInfoVo tutorVo : tSdtTutorPrentInfoPageList) {
                        if (id.equals(tutorVo.getId())) {
                            //如果id相等,则组合徒弟数据
                            SdtPrentInfoVo prentVo = new SdtPrentInfoVo();
                            prentVo.setPrentName(tutorVo.getUserName());//徒弟姓名
                            prentVo.setPrentAwardName(tutorVo.getPrentAwardName());//徒弟获得奖励信息
                            sdtPrentInfoVos.add(prentVo);
                        }
                    }
                    tutorNew.setSdtPrentInfos(sdtPrentInfoVos);
                    //将徒弟信息放入docx中
                    if (sdtPrentInfoVos != null && sdtPrentInfoVos.size() > 0) {
                        tutorNew.setSdtPrentsEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/sdtTutorPrentInfoPerson_segment.docx"), sdtPrentInfoVos));
                    }
                    //将师带徒信息放入新的师带徒集合中
                    tSdtTutorPrentInfoListNew.add(tutorNew);
                }
            }
        }

//        List<EmpBaseInfoVo> tEmpBaseInfoPageList = humanDataDao.getTEmpBaseInfoPageList(erpNo);
        if (tEmpBaseInfoPageList != null && tEmpBaseInfoPageList.size() > 0) {
            for (EmpBaseInfoVo vo : tEmpBaseInfoPageList) {
                vo.setSex(getNameByValue("Gender", vo.getSex(), map));
                vo.setNation(getNameByValue("Nation", vo.getNation(), map));
                vo.setPolitiStatus(getNameByValue("PoliticalLandscapeText", vo.getPolitiStatus(), map));
            }
        }
//        List<ContestInfoVo> tContestInfoPageList = humanDataDao.getTContestInfoPageList(erpNo);
        if (tContestInfoPageList != null && tContestInfoPageList.size() > 0) {
            for (ContestInfoVo vo : tContestInfoPageList) {
                vo.setAwardLevel(getNameByValue("JygexinQcJb", vo.getAwardLevel(), map));
                vo.setCompRank(getNameByValue("JygexinQcDj", vo.getCompRank(), map));
            }
        }

//        List<AcadeAchiveInfoVo> tAcadeAchiveInfoPageList = humanDataDao.getTAcadeAchiveInfoPageList(erpNo);
        if (tAcadeAchiveInfoPageList != null && tAcadeAchiveInfoPageList.size() > 0) {
            List<String> ids = new ArrayList<>();
            for (AcadeAchiveInfoVo vo : tAcadeAchiveInfoPageList) {
                vo.setAcadType(getNameByValue("XueshuchengguoType", vo.getAcadType(), map));
                vo.setLevel(getNameByValue("XueshuchengguoJb", vo.getLevel(), map));
                vo.setRole(getNameByValue("XueshuchengguoJs", vo.getRole(), map));
                ids.add(vo.getId());
            }
            //根据专利id查询参与人
            List<TPartRank> tPartRankByMids = tPartRankDao.getTPartRankByMids(ids, "12");
            if (tPartRankByMids != null && tPartRankByMids.size() > 0) {
                for (AcadeAchiveInfoVo vo : tAcadeAchiveInfoPageList) {
                    List<TPartRank> tPartRanks = new ArrayList<>();
                    //便利查询到的参与人集合,如果参与人的item_id等于任务id,则说明是该任务的参与人
                    for (TPartRank tPartRank : tPartRankByMids) {
                        tPartRank.setRole(getNameByValue("XueshuchengguoJs", tPartRank.getRole(), map));
                        if (vo.getId().equals(tPartRank.getItemId())) {
                            tPartRanks.add(tPartRank);
                        }
                    }
                    //将人员集合放入导出中
                    if (tPartRanks != null && tPartRanks.size() > 0) {
                        vo.setAcadeAchivePersonEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/acadeAchiveIPerson_segment.docx"), tPartRanks));
                    }
                }
            }
        }

//        List<ContiStudyInfoVo> tContiStudyInfoPageList = humanDataDao.getTContiStudyInfoPageList(erpNo);
        if (tContiStudyInfoPageList != null && tContiStudyInfoPageList.size() > 0) {
            for (ContiStudyInfoVo vo : tContiStudyInfoPageList) {
                vo.setType(getNameByValue("PeixunshoukeType", vo.getType(), map));
            }
        }

//        List<EducateInfoVo> tEducateInfoPageList = humanDataDao.getTEducateInfoPageList(erpNo);
        if (tEducateInfoPageList != null && tEducateInfoPageList.size() > 0) {
            for (EducateInfoVo vo : tEducateInfoPageList) {
                vo.setSchoolType(getNameByValue("CollegeCategory", vo.getSchoolType(), map));
                vo.setEducName(getNameByValue("PersonnelQualifications", vo.getEducName(), map));
                vo.setDegreeName(getNameByValue("AcademicDegree", vo.getDegreeName(), map));
            }
        }

//        List<ExpertTitleInfoVo> tExpertTitleInfoPageList = humanDataDao.getTExpertTitleInfoPageList(erpNo);
        if (tExpertTitleInfoPageList != null && tExpertTitleInfoPageList.size() > 0) {
            for (ExpertTitleInfoVo vo : tExpertTitleInfoPageList) {
                vo.setEmpTitle(getNameByValue("TalentTitle", vo.getEmpTitle(), map));
                vo.setMajor(getNameByValue("ProWorkTypes", vo.getMajor(), map));
                vo.setType(getNameByValue("ExpertCategory", vo.getType(), map));
                vo.setLevelName(getNameByValue("ExpertLevel", vo.getLevelName(), map));
            }
        }

//        List<HonorInfoVo> tHonorInfoPageList = humanDataDao.getTHonorInfoPageList(erpNo);
        if (tHonorInfoPageList != null && tHonorInfoPageList.size() > 0) {
            for (HonorInfoVo vo : tHonorInfoPageList) {
                vo.setHonorLevel(getNameByValue("JygexinQcJb", vo.getHonorLevel(), map));
                vo.setHonorType(getNameByValue("RuYuLeiBie", vo.getHonorType(), map));
            }
        }

//        List<PatentInfoVo> tPatentInfoPageList = humanDataDao.getTPatentInfoPageList(erpNo);
        if (tPatentInfoPageList != null && tPatentInfoPageList.size() > 0) {
            List<String> ids = new ArrayList<>();
            for (PatentInfoVo vo : tPatentInfoPageList) {
                vo.setPatentType(getNameByValue("PatentType", vo.getPatentType(), map));
                ids.add(vo.getId());
            }
            //根据专利id查询参与人
            List<TPartRank> tPartRankByMids = tPartRankDao.getTPartRankByMids(ids, "14");
            for (PatentInfoVo vo : tPatentInfoPageList) {
                List<TPartRank> tPartRanks = new ArrayList<>();
                //便利查询到的参与人集合,如果参与人的item_id等于任务id,则说明是该任务的参与人
                for (TPartRank tPartRank : tPartRankByMids) {
                    if (vo.getId().equals(tPartRank.getItemId())) {
                        tPartRanks.add(tPartRank);
                    }
                }
                //将人员集合存入对应的任务中
                vo.setPersons(tPartRanks);
                //将人员集合放入导出中
                if (tPartRanks != null && tPartRanks.size() > 0) {
                    vo.setPatentPersonEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/patentperson_segment.docx"), tPartRanks));
                }
            }
        }

//        List<ProTecInfoVo> tProTecInfoPageList = humanDataDao.getTProTecInfoPageList(erpNo);
        if (tProTecInfoPageList != null && tProTecInfoPageList.size() > 0) {
            for (ProTecInfoVo vo : tProTecInfoPageList) {
                vo.setSubjSet(getNameByValue("ProTechnicalQualifications", vo.getSubjSet(), map));
                vo.setSubjLevel(getNameByValue("ProfessionalQualifications", vo.getSubjLevel(), map));
                vo.setOrgLevel(getNameByValue("IdentificationUnitLevel", vo.getOrgLevel(), map));
            }
        }

//        List<ProjAchieveInfoVo> tProjAchieveInfoPageList = humanDataDao.getTProjAchieveInfoPageList(erpNo);
        if (tProjAchieveInfoPageList != null && tProjAchieveInfoPageList.size() > 0) {
            List<String> ids = new ArrayList<>();
            for (ProjAchieveInfoVo vo : tProjAchieveInfoPageList) {
                vo.setProjLevel(getNameByValue("StandardLevel", vo.getProjLevel(), map));
                vo.setRole(getNameByValue("XiangMuKeTiJS", vo.getRole(), map));
                ids.add(vo.getId());
            }
            //根据专利id查询参与人
            List<TPartRank> tPartRankByMids = tPartRankDao.getTPartRankByMids(ids, "17");
            if (tPartRankByMids != null && tPartRankByMids.size() > 0) {
                for (ProjAchieveInfoVo vo : tProjAchieveInfoPageList) {
                    List<TPartRank> tPartRanks = new ArrayList<>();
                    //便利查询到的参与人集合,如果参与人的item_id等于任务id,则说明是该任务的参与人
                    for (TPartRank tPartRank : tPartRankByMids) {
                        tPartRank.setRole(getNameByValue("XiangMuKeTiJS", tPartRank.getRole(), map));
                        if (vo.getId().equals(tPartRank.getItemId())) {
                            tPartRanks.add(tPartRank);
                        }
                    }
                    //将人员集合放入导出中
                    if (tPartRanks != null && tPartRanks.size() > 0) {
                        vo.setProjAchievePersonEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/projAchievePerson_segment.docx"), tPartRanks));
                    }
                }
            }
        }

//        List<SkillLevelInfoVo> tSkillLevelInfoPageList = humanDataDao.getTSkillLevelInfoPageList(erpNo);
        if (tSkillLevelInfoPageList != null && tSkillLevelInfoPageList.size() > 0) {
            for (SkillLevelInfoVo vo : tSkillLevelInfoPageList) {
                vo.setTechType(getNameByValue("SkillAppraisalWork", vo.getTechType(), map));
                vo.setQualifiLevel(getNameByValue("QualificationLevel", vo.getQualifiLevel(), map));
                vo.setOrgLevel(getNameByValue("IdentificationUnitLevel", vo.getOrgLevel(), map));
            }
        }

//        List<StandInfoVo> tStandInfoPageList = humanDataDao.getTStandInfoPageList(erpNo);
        if (tStandInfoPageList != null && tStandInfoPageList.size() > 0) {
            List<String> ids = new ArrayList<>();
            for (StandInfoVo vo : tStandInfoPageList) {
                vo.setType(getNameByValue("ZdbzType", vo.getType(), map));
                vo.setLevel(getNameByValue("JygexinQcJb", vo.getLevel(), map));
                vo.setRole(getNameByValue("XueshuchengguoJs", vo.getRole(), map));
                ids.add(vo.getId());
            }
            //根据专利id查询参与人
            List<TPartRank> tPartRankByMids = tPartRankDao.getTPartRankByMids(ids, "13");
            if (tPartRankByMids != null && tPartRankByMids.size() > 0) {
                for (StandInfoVo vo : tStandInfoPageList) {
                    List<TPartRank> tPartRanks = new ArrayList<>();
                    //便利查询到的参与人集合,如果参与人的item_id等于任务id,则说明是该任务的参与人
                    for (TPartRank tPartRank : tPartRankByMids) {
                        tPartRank.setRole(getNameByValue("XueshuchengguoJs", tPartRank.getRole(), map));
                        if (vo.getId().equals(tPartRank.getItemId())) {
                            tPartRanks.add(tPartRank);
                        }
                    }
                    //将人员集合放入导出中
                    if (tPartRanks != null && tPartRanks.size() > 0) {
                        vo.setStandPersonEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/standPerson_segment.docx"), tPartRanks));
                    }
                }
            }
        }

//        List<TecInnovInfoVo> tTecInnovInfoPageList = humanDataDao.getTTecInnovInfoPageList(erpNo);
        if (tTecInnovInfoPageList != null && tTecInnovInfoPageList.size() > 0) {
            List<String> ids = new ArrayList<>();
            for (TecInnovInfoVo vo : tTecInnovInfoPageList) {
                vo.setAwardLevel(getNameByValue("JygexinQcJb", vo.getAwardLevel(), map));
                vo.setAwardGrade(getNameByValue("JygexinQcDj", vo.getAwardGrade(), map));
                ids.add(vo.getId());
            }
            //根据专利id查询参与人
            List<TPartRank> tPartRankByMids = tPartRankDao.getTPartRankByMids(ids, "15");
            if (tPartRankByMids != null && tPartRankByMids.size() > 0) {
                for (TecInnovInfoVo vo : tTecInnovInfoPageList) {
                    List<TPartRank> tPartRanks = new ArrayList<>();
                    //便利查询到的参与人集合,如果参与人的item_id等于任务id,则说明是该任务的参与人
                    for (TPartRank tPartRank : tPartRankByMids) {
                        if (vo.getId().equals(tPartRank.getItemId())) {
                            tPartRanks.add(tPartRank);
                        }
                    }
                    //将人员集合放入导出中
                    if (tPartRanks != null && tPartRanks.size() > 0) {
                        vo.setTecInnovPersonEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/tecInnovPerson_segment.docx"), tPartRanks));
                    }
                }
            }
        }

//        List<TecManInnovVo> tTecManInnovPageList = humanDataDao.getTTecManInnovPageList(erpNo);
        if (tTecManInnovPageList != null && tTecManInnovPageList.size() > 0) {
            List<String> ids = new ArrayList<>();
            for (TecManInnovVo vo : tTecManInnovPageList) {
                vo.setAchiType(getNameByValue("KjglAchiveType", vo.getAchiType(), map));
                vo.setAwardLevel(getNameByValue("JygexinQcJb", vo.getAwardLevel(), map));
                vo.setAwardGrade(getNameByValue("JygexinQcDj", vo.getAwardGrade(), map));
                ids.add(vo.getId());
            }
            //根据专利id查询参与人
            List<TPartRank> tPartRankByMids = tPartRankDao.getTPartRankByMids(ids, "16");
            if (tPartRankByMids != null && tPartRankByMids.size() > 0) {
                for (TecManInnovVo vo : tTecManInnovPageList) {
                    List<TPartRank> tPartRanks = new ArrayList<>();
                    //便利查询到的参与人集合,如果参与人的item_id等于任务id,则说明是该任务的参与人
                    for (TPartRank tPartRank : tPartRankByMids) {
                        if (vo.getId().equals(tPartRank.getItemId())) {
                            tPartRanks.add(tPartRank);
                        }
                    }
                    //将人员集合放入导出中
                    if (tPartRanks != null && tPartRanks.size() > 0) {
                        vo.setTecManPersonEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/tecManInnovPerson_segment.docx"), tPartRanks));
                    }
                }
            }
        }

//        List<WorkExpInfoVo> tWorkExpInfoPageList = humanDataDao.getTWorkExpInfoPageList(erpNo);
        if (tWorkExpInfoPageList != null && tWorkExpInfoPageList.size() > 0) {
            for (WorkExpInfoVo vo : tWorkExpInfoPageList) {
                vo.setRank(getNameByValue("DutyLevel", vo.getRank(), map));
                vo.setPostType(getNameByValue("PostCategory", vo.getPostType(), map));
            }
        }

//        List<YearEffectInfoVo> tYearEffectInfoPageList = humanDataDao.getTYearEffectInfoPageList(erpNo);
        if (tYearEffectInfoPageList != null && tYearEffectInfoPageList.size() > 0) {
            for (YearEffectInfoVo vo : tYearEffectInfoPageList) {
                vo.setPerforGrade(getNameByValue("PerformLevelRecentThreeYears", vo.getPerforGrade(), map));
            }
        }

//        List<SdtTutorPrentInfoVo> tSdtTutorPrentInfoPageList = humanDataDao.getTSdtTutorPrentInfoPageList(erpNo);

        //拼装数据
        if (tEmpBaseInfoPageList == null || tEmpBaseInfoPageList.size() < 1) {
//            return null;
            tEmpBaseInfoPageList = new ArrayList<>();
            tEmpBaseInfoPageList.add(new EmpBaseInfoVo());
        }
        log.info("组装模板数据");
        EmpBaseInfoVo empBaseInfoVo = tEmpBaseInfoPageList.get(0);
        if (tContiStudyInfoPageList != null && tContiStudyInfoPageList.size() > 0) {
//            empBaseInfoVo.setContiStudyInfoEx(new DocxRenderData(new File(pathOfTemplate + "contiStudyInfo_segment.docx"), tContiStudyInfoPageList));
            empBaseInfoVo.setContiStudyInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/contiStudyInfo_segment.docx"), tContiStudyInfoPageList));
        }
        log.info("组装模板数据2");
        if (tEducateInfoPageList != null && tEducateInfoPageList.size() > 0) {
//            empBaseInfoVo.setEducateInfoEx(new DocxRenderData(new File(pathOfTemplate+"educateInfo_segment.docx"),tEducateInfoPageList));
            empBaseInfoVo.setEducateInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/educateInfo_segment.docx"), tEducateInfoPageList));
        }
        if (tExpertTitleInfoPageList != null && tExpertTitleInfoPageList.size() > 0) {
//            empBaseInfoVo.setExpertTitleInfoEx(new DocxRenderData(new File(pathOfTemplate+"expertTitleInfo_segment.docx"),tExpertTitleInfoPageList));
            empBaseInfoVo.setExpertTitleInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/expertTitleInfo_segment.docx"), tExpertTitleInfoPageList));
        }
        if (tHonorInfoPageList != null && tHonorInfoPageList.size() > 0) {
//            empBaseInfoVo.setHonorInfoEx(new DocxRenderData(new File(pathOfTemplate+"honorInfo_segment.docx"),tHonorInfoPageList));
            empBaseInfoVo.setHonorInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/honorInfo_segment.docx"), tHonorInfoPageList));
        }
        if (tPatentInfoPageList != null && tPatentInfoPageList.size() > 0) {
//            empBaseInfoVo.setPatentInfoEx(new DocxRenderData(new File(pathOfTemplate+"patentInfo_segment.docx"),tPatentInfoPageList));
            empBaseInfoVo.setPatentInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/patentInfo_segment.docx"), tPatentInfoPageList));
        }
        if (tProjAchieveInfoPageList != null && tProjAchieveInfoPageList.size() > 0) {
//            empBaseInfoVo.setProjAchieveInfoEx(new DocxRenderData(new File(pathOfTemplate+"projAchieveInfo_segment.docx"),tProjAchieveInfoPageList));
            empBaseInfoVo.setProjAchieveInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/projAchieveInfo_segment.docx"), tProjAchieveInfoPageList));
        }
        if (tProTecInfoPageList != null && tProTecInfoPageList.size() > 0) {
//            empBaseInfoVo.setProTecInfoEx(new DocxRenderData(new File(pathOfTemplate+"proTecInfo_segment.docx"),tProTecInfoPageList));
            empBaseInfoVo.setProTecInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/proTecInfo_segment.docx"), tProTecInfoPageList));
        }
        if (tSkillLevelInfoPageList != null && tSkillLevelInfoPageList.size() > 0) {
//            empBaseInfoVo.setSkillLevelInfoEx(new DocxRenderData(new File(pathOfTemplate+"skillLevelInfo_segment.docx"),tSkillLevelInfoPageList));
            empBaseInfoVo.setSkillLevelInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/skillLevelInfo_segment.docx"), tSkillLevelInfoPageList));
        }
        if (tStandInfoPageList != null && tStandInfoPageList.size() > 0) {
//            empBaseInfoVo.setStandInfoEx(new DocxRenderData(new File(pathOfTemplate+"standInfo_segment.docx"),tStandInfoPageList));
            empBaseInfoVo.setStandInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/standInfo_segment.docx"), tStandInfoPageList));
        }
        if (tTecInnovInfoPageList != null && tTecInnovInfoPageList.size() > 0) {
//            empBaseInfoVo.setTecInnovInfoEx(new DocxRenderData(new File(pathOfTemplate+"tecInnovInfo_segment.docx"),tTecInnovInfoPageList));
            empBaseInfoVo.setTecInnovInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/tecInnovInfo_segment.docx"), tTecInnovInfoPageList));
        }
        if (tTecManInnovPageList != null && tTecManInnovPageList.size() > 0) {
//            empBaseInfoVo.setTecManInnovEx(new DocxRenderData(new File(pathOfTemplate+"tecManInnov_segment.docx"),tTecManInnovPageList));
            empBaseInfoVo.setTecManInnovEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/tecManInnov_segment.docx"), tTecManInnovPageList));
        }
        if (tWorkExpInfoPageList != null && tWorkExpInfoPageList.size() > 0) {
//            empBaseInfoVo.setWorkExpInfoEx(new DocxRenderData(new File(pathOfTemplate+"workExpInfo_segment.docx"),tWorkExpInfoPageList));
            empBaseInfoVo.setWorkExpInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/workExpInfo_segment.docx"), tWorkExpInfoPageList));
        }
        if (tYearEffectInfoPageList != null && tYearEffectInfoPageList.size() > 0) {
//            empBaseInfoVo.setYearEffectInfoEx(new DocxRenderData(new File(pathOfTemplate+"yearEffectInfo_segment.docx"),tYearEffectInfoPageList));
            empBaseInfoVo.setYearEffectInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/yearEffectInfo_segment.docx"), tYearEffectInfoPageList));
        }
        if (tSdtTutorPrentInfoPageList != null && tSdtTutorPrentInfoPageList.size() > 0) {
//            empBaseInfoVo.setSdtTutorPrentInfoEx(new DocxRenderData(new File(pathOfTemplate+"sdtTutorPrentInfo_segment.docx"),tSdtTutorPrentInfoPageList));
//            empBaseInfoVo.setSdtTutorPrentInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/sdtTutorPrentInfo_segment.docx"), tSdtTutorPrentInfoPageList));
            empBaseInfoVo.setSdtTutorPrentInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/sdtTutorPrentInfo_segment.docx"), tSdtTutorPrentInfoListNew));
        }
        if (tContestInfoPageList != null && tContestInfoPageList.size() > 0) {
//            empBaseInfoVo.setContestInfoEx(new DocxRenderData(new File(pathOfTemplate+"contestInfo_segment.docx"),tContestInfoPageList));
            empBaseInfoVo.setContestInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/contestInfo_segment.docx"), tContestInfoPageList));
        }
        if (tAcadeAchiveInfoPageList != null && tAcadeAchiveInfoPageList.size() > 0) {
//            empBaseInfoVo.setAcadeAchiveInfoEx(new DocxRenderData(new File(pathOfTemplate+"acadeAchiveInfo_segment.docx"),tAcadeAchiveInfoPageList));
            empBaseInfoVo.setAcadeAchiveInfoEx(new DocxRenderData(HumanDataServiceImpl.class.getClassLoader().getResourceAsStream("templates/acadeAchiveInfo_segment.docx"), tAcadeAchiveInfoPageList));
        }

        log.info("数据组装完成*************");
        return empBaseInfoVo;
    }

    @Override
    public List<EmpBaseInfoVo> getTEmpBaseInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTEmpBaseInfoPageList(erpNo, deptId);
    }

    @Override
    public List<EducateInfoVo> getTEducateInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTEducateInfoPageList(erpNo, deptId);
    }

    @Override
    public List<WorkExpInfoVo> getTWorkExpInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTWorkExpInfoPageList(erpNo, deptId);
    }

    @Override
    public List<ContiStudyInfoVo> getTContiStudyInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTContiStudyInfoPageList(erpNo, deptId);
    }

    @Override
    public List<HonorInfoVo> getTHonorInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTHonorInfoPageList(erpNo, deptId);
    }

    @Override
    public List<ContestInfoVo> getTContestInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTContestInfoPageList(erpNo, deptId);
    }

    @Override
    public List<ExpertTitleInfoVo> getTExpertTitleInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTExpertTitleInfoPageList(erpNo, deptId);
    }

    @Override
    public List<ProTecInfoVo> getTProTecInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTProTecInfoPageList(erpNo, deptId);
    }

    @Override
    public List<SkillLevelInfoVo> getTSkillLevelInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTSkillLevelInfoPageList(erpNo, deptId);
    }

    @Override
    public List<SdtTutorPrentInfoVo> getTSdtTutorPrentInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTSdtTutorPrentInfoPageList(erpNo, deptId);
    }

    @Override
    public List<YearEffectInfoVo> getTYearEffectInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTYearEffectInfoPageList(erpNo, deptId);
    }

    @Override
    public List<AcadeAchiveInfoVo> getTAcadeAchiveInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTAcadeAchiveInfoPageList(erpNo, deptId);
    }

    @Override
    public List<StandInfoVo> getTStandInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTStandInfoPageList(erpNo, deptId);
    }

    @Override
    public List<PatentInfoVo> getTPatentInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTPatentInfoPageList(erpNo, deptId);
    }

    @Override
    public List<TecInnovInfoVo> getTTecInnovInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTTecInnovInfoPageList(erpNo, deptId);
    }

    @Override
    public List<TecManInnovVo> getTTecManInnovPageList(String erpNo, String deptId) {
        return humanDataDao.getTTecManInnovPageList(erpNo, deptId);
    }

    @Override
    public List<ProjAchieveInfoVo> getTProjAchieveInfoPageList(String erpNo, String deptId) {
        return humanDataDao.getTProjAchieveInfoPageList(erpNo, deptId);
    }


//    @Override
//    public List<FileInfoVo> getFileList(String sysCode, String businessId, String businessNode) {
////        ResultData fileList = fileServerCall.findFileList("ubiquitous_project", "5f3badff005449f2b780fed5a0d92b4d", "ub_declaration_file");
//        //查询业务id对应的文件列表
//        ResultData fileList = fileServerCall.findFileList(sysCode, businessId, businessNode);
////        System.out.println(fileList);
//        //055f503d4bf240e8ad26859c275700ee  fileId   filename  newFileName -> 055f503d4bf240e8ad26859c275700ee.png
//        JSONArray jsonArray = JSONArray.fromObject(fileList.getData());
//        JSONObject jsonObject = JSONObject.fromObject(jsonArray.get(0));
//        List<FileInfoVo> files = new ArrayList<>();
//        jsonArray.forEach(p -> {
//            FileInfoVo fileInfoVo = new FileInfoVo();
//            JSONObject jsonObj = JSONObject.fromObject(p);
//            fileInfoVo.setId(jsonObj.get("id").toString());
//            fileInfoVo.setExtName(jsonObj.get("extName").toString());
//            fileInfoVo.setNewFileName(jsonObj.get("newFileName").toString());
//            fileInfoVo.setOldFileName(jsonObj.get("oldFileName").toString());
//            files.add(fileInfoVo);
//        });
//        System.out.println(files);
//
//        //遍历获取到的文件列表下载到本地
//        files.forEach(p -> {
//            //调用文件服务根据id下载
//            Response.Body fileResponse = fileServerCall.download(p.getId()).body();
//            try (
//                    InputStream inputStream = fileResponse.asInputStream();
//            ) {
//                writeToLocal("D:/" + p.getNewFileName(), inputStream);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        });


//        return files;
//
//    }

    private void writeToLocal(String destination, InputStream input)
            throws IOException {
        int index;
        byte[] bytes = new byte[1024];
        FileOutputStream downloadFile = new FileOutputStream(destination);
        while ((index = input.read(bytes)) != -1) {
            downloadFile.write(bytes, 0, index);
            downloadFile.flush();
        }
        downloadFile.close();
        input.close();
    }

//    @Override
//    public void getFileList(HttpServletResponse response) {
////        ResultData fileList = fileServerCall.findFileList("ubiquitous_project", "5f3badff005449f2b780fed5a0d92b4d", "ub_declaration_file");
////        System.out.println(fileList);
//        //055f503d4bf240e8ad26859c275700ee  fileId   filename  newFileName -> 055f503d4bf240e8ad26859c275700ee.png
//
////        Response.Body fileResponse = fileServerCall.download("055f503d4bf240e8ad26859c275700ee").body();
////        Response.Body fileResponse = fileServerCall.download("0b6456f02b19443d963f2b5bb0fb885a").body();
//        Response.Body fileResponse = fileServerCall.download("eaef2b0499154e189c1e8d491ff755d9").body();
////        Response.Body fileResponse = fileServerCall.download("652c772a86114d6581f86f009971200b").body();
////        Response.Body fileResponse = fileServerCall.download("0fb4305850fe4798aca0092a1a054210").body();
//        try (InputStream inputStream = fileResponse.asInputStream();
//             ServletOutputStream outputStream = response.getOutputStream()
//        ) {
//
//            response.setContentType("image/png");
//            outputStream.write(IOUtils.toByteArray(inputStream));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }

    /**
     * 获取name值
     *
     * @param name
     * @param dictValue
     * @return
     */
    public static String getNameByValue(String name, String dictValue, Map<String, List<SysDictionaryInfoVo>> map) {
        List<SysDictionaryInfoVo> entityList = map.get(name);
        String dictName = "";
        if (dictValue != null) {
            if (entityList != null && entityList.size() > 0) {
                for (int i = 0; i < entityList.size(); i++) {
                    SysDictionaryInfoVo entity = JSONObject.parseObject(JSON.toJSONString(entityList.get(i)), SysDictionaryInfoVo.class);
                    if (dictValue.equals(entity.getValue())) {
                        dictName = entity.getName();
                        return dictName;
                    }
                }
            }
        }
//        return null;
//        return "";
        return dictValue;
    }

	@Override
	public void deleteTSdtAwardBySdtTdId(String id) {
		humanDataDao.deleteTSdtAwardBySdtTdId(id);
	}
}
